from PyQt5 import QtCore
import decimal
import logging
config=None
mainw=None
server=None
# class MySet:
#     def __init__(self,data=[]):
#         self._data=data
#     def __iter__(self):
#         return iter(self._data)
#     def __str__(self):
#         return "myset:"+str(self._data)
#     # def __next__(self): 
#     #     if self.num > self.end:
#     #         raise StopIteration
#     #     else:
#     #         self.num += 1
#     #         return self.num - 1
#     # def count(self,v):
#     #     if v in self._data:
#     #         return 1
#     #     return 0
#     def erase(self,v):
#         self._data.remove(v)
#         pass
#     def prepend(self,v):
#         self._data.insert(0,v)
#     def append(self,datas):
#         it = datas.begin()
#         if it is None:
#             return
#         while (it != datas.end()):
#             self.insert(datas.at(it))
#             it+=1
#     def insert(self,v):
#         # logging.info([v,self._data])
#         # if v in self._data:
#         #     logging.info("already in")
#         #     pass
#         # else:
#         self._data.append(v)
#         # self._data.sort()
#         # logging.info(self._data)
#     def insert_at(self,row,v):
#         # print("insert_at========")
#         # print(self._data,row,v)
#         self._data.insert(row,v)
#         # print(self._data)
#         # print("end insert_at")
#     def size(self):
#         # print(self._data)
#         return len(self._data)
#     def count(self):
#         # print(self._data)
#         return len(self._data)
#     def empty(self):
#         if len(self._data)==0:
#             return True
#         else:
#             return False
#     def begin(self):
#         if self.size()>0:
#             return 0
#         else:
#             return None
#     def at(self,i):
#         if i>=0 and i<len(self._data):
#             return self._data[i]
#         else:
#             return None
#     def end(self):
#         if self.size()>0:
#             return len(self._data)
#         else:
#             return None
#     def rbegin(self):
#         return self.end()
#     def rend(self):
#         return self.begin()
#     def clear(self):
#         self._data=[]
#     pass
def timestr():
    db = QtCore.QDateTime.currentDateTime()
    db_str = db.toString("yyyy_MM_dd_hh_mm_ss")
    return db_str
def in_list(one, l1):
    for i in range(len(l1)):
        # logging.info(str(one)+str(l1[i]))
        if one in l1[i]:
            return i
    return -1
def myfloat(f):
    try:
        r = float(f)
    except ValueError:
        r = 0
    except TypeError:
        r=0
    return r
def is_float(a_string):
    try:
        float(a_string)
        return True
    except TypeError:
        return False
    except ValueError:
        return False    
def isfloat(f):
    try:
        r = float(f)
        return True
    except ValueError:
        return False
def inItems(items, one):
    for s in items:
        if s[0] == one[0] and s[1] == one[1]:
            return True
    return False    
def isDev():
    try:
        from getmac import get_mac_address
        mac=get_mac_address()
        print(mac)
        if mac in ['00:e1:8c:ea:99:5d']:
            return True
        else:
            return False    
    except ModuleNotFoundError:
        return False

def valid_count(num_str,p):
    if num_str=="":
        return ""
    d=decimal.Context(prec=p,rounding=decimal.ROUND_HALF_EVEN).create_decimal(num_str)
    d=remove_exponent(d)
    r=str(d)
    return r
def point_count(num_str,p):
    if num_str=="":
        return ""
    zstr="0."+p*"0"
    logging.info([num_str,p,zstr])
    d=decimal.Decimal(num_str).quantize(decimal.Decimal(zstr),rounding=decimal.ROUND_HALF_EVEN)
    d=remove_exponent(d)
    r=str(d)
    return r
def remove_exponent(d):
    return d.quantize(decimal.Decimal(1)) if d == d.to_integral() else d.normalize()
def ppmTopc(ppmstr):
    d=decimal.Decimal(ppmstr)
    d=d/10000
    print(dir(d))
    d=remove_exponent(d)
    r=str(d)
    return r
if __name__=="__main__":
    # print(ppmTopc("3.12"))
    a=MySet([1,2,3])
    print(a)
    for a1 in a:
        print(a1)
